package com.zhangqie.dnui.demo2.demo3;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * Created by zhangqie on 2018/9/20
 * Describe:
 */
public class A {

    public static void stringSort(String str,boolean desc){
        char[] array=str.toCharArray();
        if(desc){//从小到大排序
            for (int i = 0; i <array.length; i++) {
                for(int j=0;j<array.length-i-1;j++){
                    if(array[j]>array[j+1]){
                        char temp=array[j];
                        array[j]=array[j+1];
                        array[j+1]=temp;
                    }
                }
            }
            System.out.print("从小到大：");
            for (int i = 0; i < array.length; i++) {
                System.out.println(array[i]);
            }
        }else{
            for (int i = 0; i < array.length; i++) {
                for(int j=0;j<array.length-1;j++){
                    if(array[i]>array[j]){
                        char temp=array[i];
                        array[i]=array[j];
                        array[j]=temp;
                    }
                }
            }
            System.out.print("从大到小：");
            for (int i = 0; i < array.length; i++) {
                System.out.println(array[i]);
            }
        }
    }

    public static void main(String []args){
        System.out.println("脚本之家测试结果：");
        char ch [] ={'A','a','b','f','m','K'};
        String add = "AbcaMCZkz";
        A.stringSort(add,true);



        //不区分大小写比较
        String source[] = { "dad", "bood", "bada", "Admin", "Aa ", "A ", "Good", "aete", "cc", "Ko", "Beta", "Could" };

        List<String> list = Arrays.asList(source);
        //String.CASE_INSENSITIVE_ORDER A在 a 前面
        Collections.sort(list, String.CASE_INSENSITIVE_ORDER);
        System.out.println(list);


    }

}
